package com.lyq.leetcode.反转链表206;

public class Main {

    public static void main(String[] args) {
        ListNode listNode1 = new ListNode(1);
        ListNode listNode2 = new ListNode(2);
        ListNode listNode3 = new ListNode(3);
        listNode1.next = listNode2;
        listNode2.next = listNode3;
        Main main = new Main();
        main.reverseList(listNode1);
    }

    public ListNode reverseList(ListNode head) {
        ListNode current = head;
        ListNode res = null;
        while (current != null) {
            ListNode temp = current.next;
            current.next = res;
            res = current;
            current = temp;
        }
        return res;
    }


    static class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }
}
